/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.A000;
import queenb.web.store.A000Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class A000Controller extends QueenbController {

    private int pa000;
    private String av001;// City Name
    private String av002;// abbreviation
    private String av003;// description
    private int fn750;// id of country
    private A000Store a000Store;
    private List<SelectItem> combolistN750 = new ArrayList<SelectItem>();
    private ComboboxUtil comboboxUtil;

    public A000Controller() {
        a000Store = new A000Store();
        comboboxUtil = new ComboboxUtil();
        Object action = getRequest().getParameter("action");
        Object pa000Object = getRequest().getParameter("pa000");
        if(action != null)
        {
            if(action.equals("edit"))
            {
                this.pa000 = Util.parseInt(pa000Object);
                getListDetalCity(pa000);
            }
        }
    }

    public void updateA000() {
        System.out.println("--------------" + pa000+av001+av002+av003+fn750);
            int count = a000Store.updateA000( this.pa000,this.av001,this.av002,this.av003,this.fn750,getLogin().getUserName());
            if (count > 0) {
                showGlobalReport(true, getResourceString("success"));
            } else {
                showGlobalReport(true, getResourceString("error"));
            }
       
        
        sendRedirectUrlTab("setting.jsp?tab=header18&linkA00="+Util.convertMD5(getRequest().getRequestURI()));

    }
    public List<A000> getListAllCity(){
        try {
            List<A000> listA000 = a000Store.getListCityALL(0,getLogin().getUserName());
            return listA000;
        } catch (Exception e) {
            return null;
        }
    }
    
    public void getListDetalCity(int id){
        try {
            List<A000> listByID = getListAllCity();
            if(listByID != null && listByID.size() > 0){
                for(int i=0; i < listByID.size();i++){
                    if(listByID.get(i).getPa000() == id){
                        this.av001 = listByID.get(i).getAv001();
                        this.av002 = listByID.get(i).getAv002();
                        this.fn750 = listByID.get(i).getFn750();
                        break;
                    }
                }
            }
        } catch (Exception e) {
        }
    }
    /**
     * @return the pa000
     */
    public int getPa000() {
        return pa000;
    }

    /**
     * @param pa000 the pa000 to set
     */
    public void setPa000(int pa000) {
        this.pa000 = pa000;
    }

    /**
     * @return the av001
     */
    public String getAv001() {
        return av001;
    }

    /**
     * @param av001 the av001 to set
     */
    public void setAv001(String av001) {
        this.av001 = av001;
    }

    /**
     * @return the av002
     */
    public String getAv002() {
        return av002;
    }

    /**
     * @param av002 the av002 to set
     */
    public void setAv002(String av002) {
        this.av002 = av002;
    }

    /**
     * @return the av003
     */
    public String getAv003() {
        return av003;
    }

    /**
     * @param av003 the av003 to set
     */
    public void setAv003(String av003) {
        this.av003 = av003;
    }

    /**
     * @return the fn750
     */
    public int getFn750() {
        return fn750;
    }

    /**
     * @param fn750 the fn750 to set
     */
    public void setFn750(int fn750) {
        this.fn750 = fn750;
    }

    /**
     * @return the combolistN750
     */
    public List<SelectItem> getCombolistN750() {
        combolistN750 = comboboxUtil.getlistCombN750();
        return combolistN750;
    }

    /**
     * @param combolistN750 the combolistN750 to set
     */
    public void setCombolistN750(List<SelectItem> combolistN750) {
        this.combolistN750 = combolistN750;
    }
}
